package com.otomotion.research.ants.information;

import java.io.Serializable;
import java.util.Vector;

/**
 * @author    joel
 */
public class Coordinate implements Serializable {
    private int x;
    private int y;
    private int z;


    public Coordinate(int x, int y, int z) {
        this.setX(x);
        this.setY(y);
        this.setZ(z);

    }


    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getZ() {
        return z;
    }

    public void setZ(int z) {
        this.z = z;
    }

    public String toString() {
        return new String(this.x + "," + this.y + "," + this.z);
    }

    public static Vector<Coordinate> getSixAdjacentCoordinates(Coordinate c) {

        Vector<Coordinate> v = new Vector<Coordinate>();
        v.add(new Coordinate(c.getX() - 1, c.getY(), c.getZ()));
        v.add(new Coordinate(c.getX() + 1, c.getY(), c.getZ()));
        v.add(new Coordinate(c.getX(), c.getY() - 1, c.getZ()));
        v.add(new Coordinate(c.getX(), c.getY() + 1, c.getZ()));
        v.add(new Coordinate(c.getX(), c.getY(), c.getZ() - 1));
        v.add(new Coordinate(c.getX(), c.getY(), c.getZ() + 1));
        return v;
    }

    public static Vector<Coordinate> getTwentySevenAdjacentCoordinates(Coordinate c) {

        int x = c.getX();
        int y = c.getY();
        int z = c.getZ();

        Vector<Coordinate> v = new Vector<Coordinate>();
        for (int i = -1; i <= 1; i++) {
            for (int j = -1; j <= 1; j++) {
                for (int k = -1; k <= 1; k++) {
                    v.add(new Coordinate(x + i, y + j, z + k));
                }
            }
        }
        return v;
    }


    /*@Override
    public int hashCode() {
        final int PRIME = 31;
        int result = 1;
        result = PRIME * result + x;
        result = PRIME * result + y;
        result = PRIME * result + z;
        return result;
    }  */


    @Override
    public boolean equals(Object obj) {

        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        final Coordinate other = (Coordinate) obj;
        if (x != other.x)
            return false;
        if (y != other.y)
            return false;
        if (z != other.z)
            return false;
        return true;
    }


    public Coordinate add(Coordinate location) {
        return new Coordinate(this.x + location.x, this.y + location.y, this.z + location.z);
    }
}

